package com.hdyg.sixg.activity.home;

import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hdyg.sixg.R;
import com.hdyg.sixg.activity.common.BaseActivity;
import com.hdyg.sixg.mvp.Contrant.CDigitalBind;
import com.hdyg.sixg.mvp.base.BasePresenter;
import com.hdyg.sixg.mvp.base.BaseUrl;
import com.hdyg.sixg.mvp.base.GetParamUtil;
import com.hdyg.sixg.mvp.base.SpMsg;
import com.hdyg.sixg.mvp.presenter.PDigitalBind;
import com.hdyg.sixg.util.StringUtil;

import butterknife.BindView;

/**
 * @author CZB
 * @describe 数字钱包绑定
 * @time 2019/4/9 10:14
 */
public class DigitalBindActivity extends BaseActivity implements CDigitalBind.IVDigitalBind {


    @BindView(R.id.ll_top_left)
    LinearLayout llTopLeft;
    @BindView(R.id.tvTopTitle)
    TextView tvTopTitle;
    @BindView(R.id.et_cash_number)
    EditText etCashNumber;
    @BindView(R.id.bt_sure)
    Button btSure;
    private String biType = ""; //eg: btc
    private String type, wallet_token;    // 请求参数所需type
    private CDigitalBind.IPDigitalBind mPresenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_digital_bind;
    }

    @Override
    protected void initView() {
        onClickListener();
        biType = getIntent().getStringExtra(SpMsg.INTENT_STR);
        type = getIntent().getStringExtra(SpMsg.INTENT_CODE);
        String title = String.format(getResources().getString(R.string.wallet_bind_title), biType);
        tvTopTitle.setText(title);
    }

    private void onClickListener() {

        llTopLeft.setOnClickListener(v -> finish());

        btSure.setOnClickListener(v -> {

            wallet_token = etCashNumber.getText().toString().trim();
            if (TextUtils.isEmpty(wallet_token)) {
                toastNotifyShort(R.string.wallet_bind_address_hint);
                return;
            }
            if (StringUtil.isFastDoubleClick()){
                return;
            }
            mPresenter.pGetDigitalBind(BaseUrl.DIGITAL_BIND_ADDRESS_URL, GetParamUtil.getDigitalBindParam(wallet_token, type));
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void createPresenter() {
        mPresenter = new PDigitalBind(this);
    }

    @Override
    public void vGetDigitalBindSuccess(String dataBeans) {
        toastNotifyShort(dataBeans);
        setResult(RESULT_OK);
        finish();
    }
}
